<?php
class App_Module_Admin_Component_Myblog_Ctrl_Http_Web extends App_Module_Admin_Component_Myblog_Ctrl_Http
{

    protected function PrimaryActionInit ($basicActionName)
    {
        Mozg::Layout('admin')->SetMenuActiveElement('articles/my_blog');

        $blog = $this->GetBlogFromQueryId();
        if (!$blog)
        {
        	$t = $this->GetTpl('Web');
        	Mozg::Response('http')->SetBody($t->NoBlogMessage());
        	return false;
        }
    }

    /**
		экшен по-умолчанию
	*/
    public function PrAction()
    {
        $this->listPr();
    }

    public function listPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
		$this->OutArticles($blog);
    }

    public function addPrAction($entry = null)
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->AddArticle($blog, $entry);
    }

    public function mediaaddPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->AddArticle($blog);
    }

    public function savePrAction ()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->SaveArticle($blog);
    }

    public function delPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelArticle($blog);
    }

    public function savethemePrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->SaveThemeArticles($blog);
    }

    public function delthemePrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelThemeArticle($blog);
    }

    public function commentslistPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->OutComments($blog);
    }

    public function delcommentPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelComment($blog);
    }

    public function editblogPrAction($blog = null)
    {
    	if (!$blog) $blog = $this->GetBlogFromQueryId();

        $t = $this->GetTpl('Editblog');
        Mozg::Response('http')->SetBody($t->GetForm($blog));

        Mozg::Layout('admin')->SetMenuActiveElement('articles/my_blog_edit');
    }

    public function saveblogPrAction()
    {
        $blog = $this->GetBlogFromQueryId();

   		$this->GetTpl('Editblog')->AddPostData($blog, (array)Mozg::Request('http')->getPost('blogdata'));

		if (Mozg_Mapper::Get('Blogs')->Save($blog))
        {
            Mozg::Lib('messanger')->createMessage(Mozg_Lang::_('DATA_SAVED'));
	       	Mozg_Router::Get('http')->Redirect(array('module' => 'admin', 'ctrl' => 'myblog'));
        }
        else
        {
        	if (!$blog->Validator()->GetState())
        	{
        		Mozg::Lib('messanger')->createMessage(Mozg_Lang::_('INVALID_DATA'), MESSAGE_ERROR);
        	}
        	else
        	{
	            Mozg::Lib('messanger')->createMessage(Mozg_Lang::_('DATA_NOT_SAVED'), MESSAGE_ERROR);
        	}

        	$this->editblogPr($blog);
            return;
        }
    }
}